var app = getApp();
Page({
    data:{
        curPage : "/zofui_sales/fenxiao/bill",
        money : 0,
        showqun : false,
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        isshowtype : false,
    },
    osShow(){
        if(this.daa.inited){
            this.onLoad();
        }
    },
    onLoad:function(options){
        var self = this;
        var zfid = options.zfid ? options.zfid : '';
        self.setData({
            options : options,
        });
        app.com.auth(function(user){
            app.com.http('fenxiao','POST',{zfid:zfid,op:'bill'},0,false,'','',function(res){
                if (!res.data.errno) {
                    self.setData({
                        userinfo : res.data.data.userinfo,
                        params : res.data.data.params,
                        sharedata : res.data.data.sharedata,
                        money : res.data.data.userinfo.money,
                        inited : true,
                    });
                    // 关闭下拉刷新
                    wx.stopPullDownRefresh();
                }else{
                    app.com.alert(res.data.message);
                }
            });
        });
        wx.setNavigationBarTitle({
          title:  '',
        });
       
    },
    formSubmit(){
        var self = this;
        var postdata = {
            op:'draw',
            money:self.data.money,
            v : 1,
            paytype : self.data.params.type ? self.data.params.type : '',
        }
        app.com.http('fenxiao','POST',postdata,0,true,'','',function(res){
            app.com.alert(res.data.message);
            if (!res.data.errno && res.data) {
                self.setData({
                    'userinfo.money' : (self.data.userinfo.money*1 - self.data.money*1).toFixed(2),
                    money : 0
                });
                var pages = getCurrentPages();
                var prevPage = pages[pages.length - 2];
                prevPage.setData({
                    'userinfo.money' : (self.data.userinfo.money*1 - self.data.money*1).toFixed(2),
                });
            }
        });
    },
    confirmpay(e){
        this.setData({
            'params.type' : e.detail.value.id,
            'params.paytypename' : e.detail.value.name,
            isshowtype : false,
        })
    },
    showtype(){
        this.setData({
            isshowtype : !this.data.isshowtype
        })
    },
    changemoney(e){
        this.setData({
            money : e.detail.value
        })
    },
    showqun(){
        this.setData({
            showqun : !this.data.showqun,
        })
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})